<?php require_once("header.php"); ?>
    <div id="content">
            <div id="post">
				<?php
					if (!isset($_SESSION['login_username'])) {
						$disabled = "disabled=true";
					}
					else {
						$disabled = "disabled=true";
					}
					
					$con = mysql_connect("localhost","progin","progin");
				
					if (!$con) {
						die('Could not connect: ' . mysql_error());
					}

					mysql_select_db("progin_171_13509045", $con) or die("Cannot find database");	

					$sql = 'SELECT * FROM konten';
					$result = mysql_query($sql);
					$contentID = $_GET['contentid'];
					$labelid = "likecount";
							
					while ($row = mysql_fetch_array($result)) {
						if (strcmp($row['id_konten'],$contentID)==0) {
							$like = $row['jumlahlike'];
							print '<div id="content-title">';
							echo $row['judul'];
							print '</div>
									<div>
										<span>posted by</span>
										<span id="content-poster" class="commentator">';
							echo $row['username'];
							print '</span>
									<div class="dateformat">';
							echo $row['tanggal'];
							echo " at ";
							echo $row['waktu'];
							print '</div>
									</div>
									<div id="content-dummy">
										<img border="0" src="'.$row['url'].'" alt="Pulpit rock" width="304" height="228" />
									</div>
									<div id="likedislike">';
							echo "<input type='button' id='likebutton' value='like' onclick=\"changeLike('$contentID', '$like', '$labelid', 'up');\" $disabled></input>
									<input type='button' id='dislikebutton' value='dislike' onclick=\"changeLike('$contentID', '$like', '$labelid', 'down');\" $disabled></input>
									<label id='$labelid'>";
							echo $row['jumlahlike'];
							print ' likes</label>
									</div>';
						}
					}
					
					echo "<div id='comment'>
								<div id='commenttext'>Comment</div>
								<div id='commentform'>
									<form id='commentformid'>
										<div><textarea id='commenttxt' name='usercomment' rows='3' cols='50'></textarea></div>
										<div><input class='actionbutton' id='commentbutton' type='button' value='Submit' name='commentsubmit' onclick=\"comment('$contentID');\" $disabled/></div>
									</form>
								</div>
								<div id='commentlist'>
									<div id='commentdiv'>";

					print "<table>";
					$sql = "INSERT INTO commentsorter SELECT * FROM komentar ORDER BY tanggal, waktu DESC";
					$result = mysql_query($sql);
					$sql= "SELECT * FROM commentsorter WHERE id_konten='$contentID'";
					$result = mysql_query($sql);
							
					while ($row = mysql_fetch_array($result)) {
						$commentID = $row['id_komentar'];
						print '<div class="commentlist">
									<div class="commentator">';
						echo $row['username'];
						print '</div>
								<div class="dateformat">';
						echo $row['tanggal'];
						echo " at ";
						echo $row['waktu'];
						print '</div>
								<div class="commenttext">';
						echo $row['komentar'];
						echo "</div>
								<input type='button' id='deletebutton' value='Delete Comment' onclick=\"deleteComment('$commentID', '$contentID');\"/></input>
								</div>";
					}
							
					print "</table>";
					
					$sql ="TRUNCATE TABLE commentsorter";
					$result = mysql_query($sql);

					mysql_close($con);
				?>
                    </div>
                </div>
            </div>
        </div>
<?php require_once("footer.php"); ?>
